let chartObj1 = null;
const loadUserOrderChartData = function (type = 'day') {
    $.get('admin/order-sale-count?type=' + type, function (res) {
        if (res.code != 0) {
            return;
        }

        if (chartObj1 == null) {
            chartObj1 = echarts.init(document.getElementById('chart1'));
        }
        let option = {

            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['销售额', '订单量']
            },
            grid: {
                left: '2%',
                right: '2%',
                bottom: '12%',
                top:'20%',
                containLabel: true
            },
            toolbox: {
                feature: {}
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: res.x_data
            },
            // yAxis: {
            //     type: 'value',
            //     // interval:10
            // },
            yAxis:[
                {
                    type: 'value',
                    name: '销售额(元)',
                    position: 'left',
                    axisLabel: {
                        formatter: '{value}'
                    },
                    alignTicks: true,
                },
                {
                    type: 'value',
                    name: '订单量(单)',
                    position: 'right',
                    axisLabel: {
                        formatter: '{value}'
                    },
                    alignTicks: true,
                }
            ],
            series: [
                {
                    name: '销售额',
                    type: 'line',
                    smooth:true,
                    data: res.y_data['pay_total'],
                    itemStyle:{
                        normal:{
                            color:'#5591c8'
                        }
                    }
                },
                {
                    name: '订单量',
                    type: 'line',
                    smooth:true,
                    data: res.y_data['order_num'],
                    itemStyle:{
                        normal:{
                            color:'#767fd0'
                        }
                    },
                    yAxisIndex: 1,
                }
            ]
        };
        // 使用刚指定的配置项和数据显示图表。
        chartObj1.setOption(option);
        window.addEventListener("resize", function () {
            chartObj1.resize();
        });
    });
}
loadUserOrderChartData();
